Field
This invention relates to stacks and more particularly relates to maintaining a context stack.
Description of the Related Art
Data sets are often used to store important personal and enterprise data. A data set may be accessed in a multi-threaded environment. In the multi-threaded environment, a single process may have multiple connections to a data set.
A process may connect to a data set using a context. As used herein a context is a data structure storing information defining communications with the data set. A process may call a Structured Query Language (SQL) function to create and attach to a context. Thereafter, the process may use the context to communicate with the data set.
Creating a context may require system significant resources. For example, a context creation function may find available memory, allocate memory, store data structures to the memory, and the like. As a result, contexts are often reused to avoid the cost of creating new contexts.
Contexts may be reused by creating a stack of contexts. A process that needs a context may retrieve an available context from the stack. When the process no longer needs the context, the process may return the context to the stack.
Unfortunately, if a large number of contexts are stored in a stack, significant resources are also used. For example, maintaining enough contexts on the stack that a context is always available may consume in excess of memory resources. However, if too few contexts are stored in the stack, significant resources are expended creating new contexts when additional numbers of contexts are acquired. For example, if too few contexts are maintained on the stack, the SQL function may be frequently employed to create additional contexts, which also consumes excess processing and memory resources.